package demo;

public class Test {
    public static void main4(String[] args) {
        Animal animal = new Dog("柯基",5);
        if(animal instanceof Dog) {
            Dog dog = (Dog) animal;
            //dog.bark();
            System.out.println("animal引用的是Dog对象");
        }else{
            System.out.println("animal引用的不是Dog这样的对象");
        }
        if(animal instanceof Bird) {
            Bird bird = (Bird) animal;
            //bird.fly();
            System.out.println("animal引用的是Bird对象");
        }else{
            System.out.println("animal引用的不是Bird这样的对象");
        }
    }
    public static Animal func2(int a){ //直接返回Animal
        if(a == 1){
            return new Dog("hhh",18);
        }else{
            return new Bird("www",10);
        }
    }

    public static void main3(String[] args) {
        func2(2);
    }
    public static void func(Animal animal){
        animal.eat();
    }
    public static void main2(String[] args) {
       // Animal dog = new Dog("旺财",20);
        Animal bird = new Bird("啾啾",19);
        func(new Dog("旺财",5));
        func(bird);

    }
    public static void main1(String[] args) {
        //Dog dog = new Dog("旺财",10);
        //dog.eat();
        Animal animal = new Dog("旺财",10);
        animal.eat();
        //animal.bark();
    }
}
